import argparse, numpy as np, pandas as pd
from scipy.spatial.distance import jensenshannon

def spec_js(df, target_hist=None, bins=10):
    if 'jmh' in df.columns and 'hmk' in df.columns:
        h, _, _ = np.histogram2d(df['jmh'], df['hmk'], bins=bins, density=True)
        p = (h.flatten()+1e-12); p = p/p.sum()
    else:
        # 无颜色时返回 0.0（不惩罚）
        return 0.0
    if target_hist is None:
        return 0.0
    q = (target_hist.flatten()+1e-12); q = q/q.sum()
    return float(jensenshannon(p,q))

if __name__ == "__main__":
    ap = argparse.ArgumentParser()
    ap.add_argument("--check", type=str, required=True)
    args = ap.parse_args()
    df = pd.read_csv(args.check)
    print("JS(spec vs target):", spec_js(df))
    print("JS 越小越好，0.0 表示完全一致")